package cn.south.campus.admin.campus.controller;

import cn.south.campus.admin.campus.model.enums.GoodsStatusEnums;
import cn.south.campus.admin.campus.model.req.GoodsReq;
import cn.south.campus.admin.campus.model.vo.GoodsVo;
import cn.south.campus.admin.campus.service.GoodsService;
import cn.south.campus.common.model.bo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/11/14 8:52
 */
@RestController
@RequestMapping("/campus/goods")
@AllArgsConstructor
public class GoodsController {
    private final GoodsService goodsService;

    @GetMapping("page")
    public Result<IPage<GoodsVo>> page(GoodsReq req) {
        IPage<GoodsVo> res = goodsService.pageQuery(req);
        return Result.success(res);
    }

    @GetMapping("detail/{id}")
    public Result<GoodsVo> detail(@PathVariable Long id) {
        GoodsVo goodsVo = goodsService.detail(id);
        return Result.success(goodsVo);
    }

    @PutMapping("offSale/{id}")
    public Result<String> offSale(@PathVariable Long id) {
        goodsService.changeStatus(GoodsStatusEnums.OFF_SALE,id);
        return Result.success("下架成功");
    }
}
